<script>

import sensors from '@/js_sdk/Sensorsdata-UniPlugin-JS/Sensorsdata-UniPlugin-JS/index';

export default {
  onLaunch(options) {
    //神策统计初始化
    let platform_type = '云采-微信小程序'

    // #ifdef H5
    platform_type = '云采-h5'
    // #endif

    // #ifdef MP-ALIPAY
    platform_type = '云采-支付宝小程序'
    // #endif

    let server_url = 'https://xinfangsheng.datasink.sensorsdata.cn/sa?project=default&token=fba64c7607e355b9';
    if (this.vuex_baseURL.webUrl == 'https://www.xfs.com') {
      server_url = 'https://xinfangsheng.datasink.sensorsdata.cn/sa?project=production&token=fba64c7607e355b9';
    }
    if(this.vuex_baseURL.webUrl == 'https://t4.fsyuncai.com'){
      server_url=''
    }
    sensors.setPara({
      server_url: server_url,
      show_log: false, //是否开启日志
      name: 'sensors',
      global_properties: { // 配置全局属性，所有上报事件属性中均会携带
        platform_type: platform_type,
        business_platform_type: '云采'
      },
      autoTrack: { //小程序全埋点配置
        appLaunch: true, // 默认为 true，false 则关闭 $MPLaunch 事件采集
        appShow: true, // 默认为 true，false 则关闭 $MPShow 事件采集
        appHide: true, // 默认为 true，false 则关闭 $MPHide 事件采集
        pageShow: true, // 默认为 true，false 则关闭 $MPViewScreen 事件采集
        pageShare: true, // 默认为 true，false 则关闭 $MPShare 事件采集
        mpClick: false, // 默认为 false，true 则开启 $MPClick 事件采集
        mpFavorite: true, // 默认为 true，false 则关闭 $MPAddFavorites 事件采集
        pageLeave: false // 默认为 false， true 则开启 $MPPageLeave事件采集
      },
      app: { // Android & iOS 初始化配置
        remote_config_url: '',
        flush_interval: 15000, //两次数据发送的最小时间间隔，单位毫秒
        flush_bulkSize: 100, //设置本地缓存日志的最大条目数，最小 50 条， 默认 100 条
        flush_network_policy: 30, //设置 flush 时网络发送策略
        auto_track: 0, // 1 应用启动， 2 应用退出，3 应用启动和退出 默认 0
        encrypt: false, //是否开启加密
        add_channel_callback_event: false, //是否开启渠道事件
        javascript_bridge: false, // WebView 打通功能
        track_crash: false, // 是否采集 AppCrash
        android: { //Android 特有配置
          session_interval_time: 30000,
          request_network: true,
          max_cache_size: 32, // 默认 32MB，最小 16MB
          mp_process_flush: false, //使用小程序 SDK 时，小程序进程是否可发送数据
        },
        ios: { //iOS 特有配置
          max_cache_size: 10000, //最大缓存条数，默认 10000 条
        }
      }
    })
    //同意隐私协议后调用进行 SDK 初始化
    sensors.init();

    // console.log(options);
    //#ifdef H5
    // 引入极光一键登录sdk
    var script1 = document.createElement('script');
    var script2 = document.createElement('script');
    var script3 = document.createElement('script');

    script1.src = 'https://jverification.jiguang.cn/scripts/jverification-web.4.0.0.min.js';
    script2.src = 'https://jverification.jiguang.cn/scripts/util/crypto-js.js';
    script3.src = 'https://opencloud.wostore.cn/h5netauth/h5login/singleton/h5auth1.min.js';
    document.body.append(script1);
    document.body.append(script2);
    document.body.append(script3);
    // 引入阿里无痕验证js
    // var script4 = document.createElement('script');
    // script4.src = 'https://g.alicdn.com/AWSC/AWSC/awsc.js';
    // script4.async = false;
    // document.body.append(script4);
    // script4.onload = function() {

    // }
    // #endif
  },
  onShow: function(options) {
    // //#ifdef H5
    // var script4 = document.createElement('script');
    // script4.src = 'https://g.alicdn.com/AWSC/AWSC/awsc.js';
    // script4.async = false;
    // document.body.append(script4);
    // script4.onload = function() {

    // }
    // // #endif
    uni.$u.vuex('vuex_imgPath', 'https://fsyuncai-file.oss-cn-beijing.aliyuncs.com/applet');
    // #ifdef MP-ALIPAY
    //获取关联普通二维码的码值，放到全局变量qrCode中
    if (options.query && options.query.qrCode) {
      const qrCode = options.query.qrCode;
      const src = decodeURIComponent(qrCode)
      if (src.includes('id')) {
        const id = src.match(/id=(\S*)/)[1]
        uni.$u.vuex('vuex_qrOrderNo', id)
      } else if (src.includes('inviteCode')) {
        const inviteCode = src.match(/inviteCode=(\S*)/)[1]
        uni.setStorageSync('inviteCode', inviteCode)
      } else {
        uni.$u.vuex('vuex_alipay_qrcode', qrCode)
      }
    }
    // #endif
    /*获取服务提供商*/
    uni.getProvider({
      service: 'oauth',
      success: function(res) {
        uni.$u.vuex('vuex_provider', res.provider[0] || 'h5');
      }
    });
    /*获取设备信息*/
    uni.getSystemInfo().then(res => {
      uni.$u.vuex('vuex_systemInfo', res);
    })
    /*获取网络状态*/
    uni.getNetworkType().then(res => {
      uni.$u.vuex('vuex_networkType', res[1].networkType);
    })
    uni.onNetworkStatusChange((res) => {
      uni.$u.vuex('vuex_networkType', res.networkType);
    });
    /*小程序升级*/
    const updateManager = uni.getUpdateManager();
    updateManager.onCheckForUpdate(function(res) {
      // 请求完新版本信息的回调
      console.log(res);
      if (res.hasUpdate) {
        updateManager.onUpdateReady(function(res) {
          uni.showModal({
            title: '更新提示',
            content: '新版本已经准备好，是否重启应用？',
            success(res) {
              if (res.confirm) {
                // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
                updateManager.applyUpdate();
              }
            }
          });
        });
        updateManager.onUpdateFailed(function(res) {
          // 新的版本下载失败
          // console.log(res);
        });
      }
    });
  },
  onHide: function() {
    // console.log('App Hide')
  },
}
</script>

<style lang="scss">
	/*每个页面公共css */
  body{
    font-size:$uni-font-size-sm;
    background:$uni-f5bg-color;
    color:$uni-text-color;
  }
  .list-bg{
    overflow: hidden;
    box-shadow: 0 0 20rpx 2rpx rgba(0,0,0,0.02);
    background:$uni-bg-color;
    border-radius:$uni-border-radius-base;
    margin:$uni-spacing-col-base $uni-spacing-row-base 0;
    .list-title{
      font-weight: bold;
      height: 86rpx;
      line-height: 86rpx;
      border-bottom:2rpx solid $uni-border-gray;
      margin:0 $uni-spacing-row-base;
      font-size:$uni-font-size-lg;
    }
  }
  .list-group-link{
    position: relative;
    .u-cell__title-text{
      font-size:$uni-font-size-sm;
      color:$uni-grey-999;
    }
    .u-cell__value{
      font-size:$uni-font-size-sm;
      color:$uni-orange;
    }
  }
  .list-group{
    font-size:$uni-font-size-sm!important;
  }
  .list-group-row {
    .list-title{
      border:0;
      font-size:$uni-font-size-base;
    }
    .number{
      float: right;
      font-weight: normal;
    }
  }
  .sticky-bottom{
    position: fixed;
    height: 100rpx;
    line-height: 100rpx;
    width:calc(100% - 80rpx);
    bottom:0;
    text-align: right;
    padding:0 40rpx 70rpx;
    z-index: 100;
    background: $uni-bg-color;
    .price{
      color:$uni-orange;
      font-size:40rpx;
    }
  }
  .btn-orange{
    padding: 0 90rpx!important;
    height: 80rpx;
    width: auto;
    background-image: linear-gradient(90deg, #FE9526 0%, #FD4304 100%);
    border-radius: 16rpx;
    border: 0!important;
    font-size: 28rpx;
    line-height: 80rpx;
    display: inline-block;
    color:$uni-text-color-inverse!important;
  }
  .btn-border-gray{
    padding: 0 90rpx!important;
    height: 80rpx;
    width: auto;
    border:2rpx solid #E5E5E5!important;
    line-height: 80rpx;
    display: inline-block;
    border-radius: $uni-border-radius-base;
    background: $uni-bg-color!important;
    font-size:$uni-font-size-base;
  }
  .uni-button:after{
    border:0;
  }
  .uni-ellipsis-1 {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .uni-ellipsis-2 {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .custom-title{
    height:40rpx;
    line-height:40rpx;
    font-size:$uni-font-size-base;
    font-weight: bold;
  }
  .clearfix:after{clear:both;content:" ";display:block;font-size:0;height:0;visibility:hidden}
  .clearfix{zoom:1}
  .btn-box{
    .btn{
      border-radius: 8rpx;
      overflow: hidden;
      background: $uni-bg-color;
    }
  }
  /deep/ .btn-boundless{border-color:#d3d3d3!important;}
  /deep/ .btn-noborder,.btn-orange{border: 0!important;border-radius: 8rpx;}

  /* CDN 服务仅供平台体验和调试使用，平台不承诺服务的稳定性，企业客户需下载字体包自行发布使用并做好备份。 */
  @font-face {
    font-family: 'xfs_iconfont';  /* Project id 3853364 */
    src: url('//at.alicdn.com/t/c/font_3853364_e4t4njcckw.woff2?t=1675838285042') format('woff2'),
        url('//at.alicdn.com/t/c/font_3853364_e4t4njcckw.woff?t=1675838285042') format('woff'),
        url('//at.alicdn.com/t/c/font_3853364_e4t4njcckw.ttf?t=1675838285042') format('truetype'),
        url('//at.alicdn.com/t/c/font_3853364_e4t4njcckw.svg?t=1675838285042#font_family') format('svg');
  }
  //提升H5端uni.toast()的层级，避免被uView的modal等遮盖
  /* #ifdef H5 */
/deep/ uni-toast {
  z-index: 999999;
}
/deep/ uni-toast .uni-toast {
  z-index: 999999;
}
/* #endif */
  .t-icon {
    background-repeat: no-repeat!important;
    background-position: center!important;
  }
</style>
